<template>
	<div class="vue_app">
		<!--头部-->
		<!-- <my-header :title="'消息详情'" :hasTitle="true" :hasBack="true" ></my-header> -->
		<!--<div style="height: 3rem;"></div>-->
		<!--头部-->
		<div class="aui-content top_div message_detail">
			<div class="message_title" style="text-align: left;">
				<h2 v-if="data">{{data.title}}</h2>
				<p v-if="data">发布日期：{{data.publishTmStr}}</p>
			</div>
			<div class="message_con" style="text-align: left;">
				<img :src="data.imgUrl"  v-if="data"/>
				<p v-html="data.content" v-if="data">{{data.content}}</p>
			</div>
		</div>
	</div>
</template>

<script>
// import {reFreshUserInfo} from '../../../utils/WXH/login.js';
import { Toast } from '../../utils/toast.js';
import {mapMutations, mapActions, mapGetters} from "vuex";
import getHrefParams from '../../utils/getUrlSearch'; 
import { CHANGE_NAVIGATION } from '../../config/postMessage-types';
import axios from 'axios';


export default {
	data () {
		return {
			data: null,
            num: null,
            enterpriseCode:''
		}
	}
    ,
    created() {
        let titleConfig = JSON.stringify({
            type: CHANGE_NAVIGATION,
            params: {
                title: "消息详情"
            }
        })
        setTimeout(() => {
            window.postMessage(titleConfig)
        },300)
    },
	mounted () {
        // await this.getUserInfo();
        // console.log(window.location.href,'进入消息详情');
        this.num = getHrefParams().rid;//获取从reactNative中传过来的参数
        this.enterpriseCode = getHrefParams().enterpriseCode;
		this.initData();
		// this.num = this.$route.query.newsId;
	}
	,
	computed:{
		...mapGetters('wxh', [
			'sessionId',
		])
	}
	,
	components:{

	},
	methods: {
		...mapActions('wxh', [
		  'getUserInfo'
		])
		,
		...mapMutations('wxh', [
		//   'USER_INFO',
		//   'ClEAR_SESSIONID',
		//   'LOGO_OUT',
		//   'LOGO_IN',
		//   'CLEAR_INFO'
		])
		,
		changeNews(num){
//			http://172.19.6.152:33004/messageVue/updateReadStatus
			let params = {
	    		rid: num  //是否分頁  false不分頁
	    	};
    		let config = {
	        	url:window.api.customer_host+"/messageVue/updateReadStatus",
	        	method: 'POST',
	        	headers: {'sessionId': this.sessionId},
	        	data:params
           	};
           	axios(config).then((res)=>{
           		console.log('刷新消息');	
           })
		},
		getNewsList(){
			let params = {
	    		isPage:"false",//是否分頁  false不分頁
	    		enterpriseCode:window.api.enterpriseCode
	    	};
           	let config = {
            	url:window.api.customer_host+"/messageVue/findMessageList",
            	method: 'POST',
            	headers: {'sessionId': this.sessionId},
            	data:params
            };
               console.log(config)
            axios(config).then((res)=>{
        		console.log(res.data.data[0].results,'saddddd')
	           	if(res.data.returncode == 0) {
					Toast({
					  message: req.errmsg,
					  type: 'fail',
					  duration: 2000
					});
					return
                }
                let arr = res.data.data[0].results;
                arr.map((item,index) => {
                    if(item.rid == this.num ){
                        this.data = item;
                    }
                })
				console.log(this.data, this.num)
				this.changeNews(this.num);
           })
		},
	    initData() {
			//调用個人中心的方法刷新用户信息 防止vuex用户信息失效
			// reFreshUserInfo(this);
			//请求消息列表
			this.getNewsList();
		}
	}
}
</script>
<style scoped="scoped">
	.vue_app{
		width: 100%;
	    height: 100%;
	    display: flex;
	    flex-direction: column;
	    align-items: center;
	    justify-content: space-between;
	}
	.message_detail{
		flex: 1;
		overflow-y: auto;
		width: 100%;
	}
	.message_detail .message_title {
	     padding-bottom:0; 
	}
</style>